/*
 *  Copyright (C) 2011 felixtheripper <felixtheripper_AT_gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/**
 *
 * @author felixtheripper
 *
 * email: felixtheripper_AT_gmail.com
 * ... please remove "_AT_" from the above string to get the right email address
 *
 */


package org.myorg.ctm.etk.gui.swg.display.menubar;

import javax.help.HelpBroker;
import javax.swing.Box;
import javax.swing.JMenuBar;
import org.myorg.shr.gui.swg.lang.IShrObj;

import org.myorg.ctm.etk.gui.swg.display.menu.*;


/**
 *
 * 
 */

abstract public class MbrPerspAbs extends JMenuBar implements IShrObj
{
    protected MbrPerspAbs()
    {
        super();

        this._menHelp_ = new MenHelpPersp();
    }

    public void setEnabledHelpGettingStarted(HelpBroker hbr)
    {
        if (this._menHelp_ != null)
            this._menHelp_.setEnabledHelpGettingStarted(hbr);
    }

    public void setEnabledHelpSourceAndTrack(HelpBroker hbr)
    {
        if (this._menHelp_ != null)
            this._menHelp_.setEnabledHelpSourceAndTrack(hbr);
    }

    @Override
    public boolean init()
    {
        if (! this._menFile.init())
            return false;

        if (this._menEdit != null)
        {
            if (! this._menEdit.init())
                return false;
        }

        if (this._menView != null)
        {
            if (! this._menView.init())
                return false;
        }

        if (this._menTools != null)
            if (! this._menTools.init())
                return false;

        if (this._menWindow != null)
        {
            if (! this._menWindow.init())
                return false;
        }

        if (! this._menHelp_.init())
            return false;


        super.add(this._menFile);

        if (this._menEdit != null)
            super.add(this._menEdit);

        if (this._menView != null)
            super.add(this._menView);

        if (this._menTools != null)
            super.add(this._menTools);

        if (this._menWindow != null)
            super.add(this._menWindow);

        super.add(Box.createHorizontalGlue());
	super.add(Box.createVerticalGlue()); // !!
        super.add(this._menHelp_);

        return true;
    }

    @Override
    public void destroy()
    {
        // TODO: update, rather iterate trough children

        if (this._menFile != null)
        {
            this._menFile.destroy();
            this._menFile = null;
        }

        if (this._menEdit != null)
        {
            this._menEdit.destroy();
            this._menEdit = null;
        }

        if (this._menTools != null)
        {
            this._menTools.destroy();
            this._menTools = null;
        }

        if (this._menWindow != null)
        {
            this._menWindow.destroy();
            this._menWindow = null;
        }

        if (this._menHelp_ != null)
        {
            this._menHelp_.destroy();
            this._menHelp_ = null;
        }
    }

    protected MenPerspFileAbs _menFile = null;
    protected MenPerspEditAbs _menEdit = null;
    protected MenViewAbs _menView = null;
    protected MenToolsAbs _menTools = null;
    protected MenWindowPerspAbs _menWindow = null;


    private MenHelpPersp _menHelp_ = null;


}
